# /**
# * Copyright (c) 2022 Beijing Jiaotong University
# * photlab is licensed under [Open Source License].
# * You can use this software according to the terms and conditions of the [Open Source License].
# *
# * You may obtain a copy of [Open Source License] at: [https://open.source.license/]
# *
# * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# *
# * See the [Open Source License] for more details.
# */
# /**
# * Author: Shihao Xie
# * Created: Jul. 5, 2022
# * Supported by: National Key Research and Development Program of China
# */


# thrift --gen py ./interface/engine_service.thrift
# thrift --gen js ./interface/engine_service.thrift
# thrift -out [output path] --gen js  [path]
# interface count = 12
namespace py phot_server.rpc.engine_service
//namespace js photlab.engine

include "graph_data_type.thrift"
include "common_data_type.thrift"
include "engine_data_type.thrift"

service Engine{

# TODO: need a task schedule or task state interface

    # add a task to engine manager
    # @param graph: the graph to calculate
    # @param task_id: the task id
    # @param priority: the task priority
    # @param execution_time: the task execution time
    # @return PhotResponse: add task response
    # exception PhotError: ...
    void add_task(1:graph_data_type.PhotGraph graph,
                  2:string task_id,
                  3:i32 priority,
                  4:i64 execution_time )
                  throws (1:common_data_type.PhotError error)

    # add a task to engine manager
    # @param graph: the graph to calculate
    # @param task_id: the task id
    # @param priority: the task priority
    # @param execution_time: the task execution time
    # @return PhotResponse: create task response
    # exception PhotError: ...
    void create_task_from_existing_graph(1:string graph_name,
                                         2:string task_id,
                                         3:i32 priority
                                         4:i32 execution_time )
                                         throws (1:common_data_type.PhotError error)

    # engine calculate a task
    # @param task_id: the task id to be calculated
    # @return PhotResponse: calculate task result response
    # exception PhotError: ...
    oneway void calculate_task(1:string task_id)

    # cancel a task to engine
    # @param task_id: the task id
    # @return PhotResponse: cancel task response
    # exception PhotError: ...
    void cancel_task(1:string task_id) throws (1:common_data_type.PhotError error)

    # cancel a task to engine
    # @param task_id: the task id
    # @return PhotResponse: pause task response
    # exception PhotError: ...
    void pause_task(1:string task_id) throws (1:common_data_type.PhotError error)

    # recover a task
    # @param task_id: the task id
    # @return PhotResponse: recover task response
    # exception PhotError: ...
    void recover_task(1:string task_id) throws (1:common_data_type.PhotError error)

    # delete a task
    # @param task_id: the task id
    # @return PhotResponse: delete task response
    # exception PhotError: ...
    void delete_task(1:string task_id) throws (1:common_data_type.PhotError error)

    # restart a task
    # @param task_id: the task id
    # @return void
    # exception PhotError: ...
    oneway void restart_task(1:string task_id)

//    # get a task result
//    # @param task_id: the task id
//    # @return PhotResponse: recover task response
//    # exception PhotError: ...
//    list<engine_data_type.PhotOutput> get_all_component_output(1:string task_id)
//                                                               throws (1:common_data_type.PhotError error)

    # get a task result
    # @param task_id: the task id
    # @param component_id: the component id to get output
    # @return PhotResponse: recover task response
    # exception PhotError: ...
    list<engine_data_type.PhotOutput> get_component_output(1:string task_id, 2:i32 component_id)
                                                           throws (1:common_data_type.PhotError error)

    # get a task result
    # @param task_id: the task id
    # @param component_id: the component id to get output
    # @return PhotResponse: recover task response
    # exception PhotError: ...
    list<engine_data_type.PhotAnalyzerOutput> get_analyzer_output(1:string task_id, 2:i32 component_id)
                                                           throws (1:common_data_type.PhotError error)

    # save a component result in a task
    # @param task_id: the task id
    # @param component_id: the component id to be got output
    # @param path: file path to output
    # @return PhotResponse: recover task response
    # exception PhotError: ...
    void save_component_output_as(1:string task_id, 2:i32 component_id, 3:string file_path)
                                  throws (1:common_data_type.PhotError error)

    # get a task result
    # @param task_id: the task id
    # @param component_id: the component id to be got output
    # @param directory_path: directory path to output
    # @return PhotResponse: recover task response
    # exception PhotError: ...
    void save_analyzer_result_as(1:string task_id, 2:i32 component_id, 3:string file_path)
                                 throws (1:common_data_type.PhotError error)

    # get a task status
    # @param task_id: the task id
    # @return PhotResponse: recover task response
    # exception PhotError: ...
    engine_data_type.PhotTaskStatus get_task_status(1:string task_id)
                                                throws (1:common_data_type.PhotError error)

    # delete a task
    # @param graph_name: the graph to be deleted
    # @param task_id: the task id
    # @return PhotResponse: recover task response
    # exception PhotError: ...
    list<string> get_task_exception_information(1:string task_id)
                                                throws (1:common_data_type.PhotError error)


}